package com.ewzj.bigdata.mvp.ui.activity

import android.content.Context
import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle

import com.ewzj.bigdata.R
import com.ewzj.bigdata.di.component.DaggerLoginComponent
import com.ewzj.bigdata.di.module.LoginModule
import com.ewzj.bigdata.mvp.contract.LoginContract
import com.ewzj.bigdata.mvp.presenter.LoginPresenter
import com.jakewharton.rxbinding2.view.RxView
import com.jess.arms.base.BaseActivity
import com.jess.arms.di.component.AppComponent
import com.umeng.socialize.UMShareAPI
import com.umeng.socialize.bean.SHARE_MEDIA
import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.activity_login.*
import java.util.concurrent.TimeUnit

class LoginActivity : BaseActivity<LoginPresenter>(),LoginContract.View {
    override fun showEnableCode(along: Long) {
        tv_verify_text.setEnabled(false)
        tv_verify_text.setTextColor(resources.getColor(R.color.color_text_gray))
        tv_verify_text.setBackgroundResource(R.drawable.tag_drawable)
        tv_verify_text.setText((60 - along).toString().plus( "秒"))
    }

    override fun showAbleCode() {
        tv_verify_text.setEnabled(true)
        tv_verify_text.setTextColor(resources.getColor(R.color.maingreen))
        tv_verify_text.setBackgroundResource(R.drawable.green_white_5)
        tv_verify_text.setText("验证")
    }

    override fun setupActivityComponent(appComponent: AppComponent?) {
        DaggerLoginComponent.builder().appComponent(appComponent)
                .loginModule(LoginModule(this))
                .build().inject(this)
    }

    override fun initData(savedInstanceState: Bundle?) {
        initClickListener()
    }

    override fun initView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_login
    }
    fun initClickListener(){
        RxView.clicks(tv_login).throttleFirst(2,TimeUnit.SECONDS).subscribe(Consumer { mPresenter.login(et_phone.text.toString(),et_verify_code.text.toString()) })
        RxView.clicks(tv_verify_text).throttleFirst(2,TimeUnit.SECONDS).subscribe(Consumer { mPresenter.sendSms(et_phone.text.toString()) })
        RxView.clicks(tv_wechat).throttleFirst(2,TimeUnit.SECONDS).subscribe(Consumer { mPresenter.initThirdLogin(SHARE_MEDIA.WEIXIN)})
        RxView.clicks(tv_qq).throttleFirst(2,TimeUnit.SECONDS).subscribe(Consumer { mPresenter.initThirdLogin(SHARE_MEDIA.QQ)})
    }
    override fun showdialog() {

    }

    override fun dismisdialog() {

    }

    override fun showLoading() {

    }

    override fun launchActivity(intent: Intent?) {

    }

    override fun hideLoading() {

    }

    override fun killMyself() {

    }

    override fun showMessage(message: String?) {

    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode,resultCode,data);
    }

    companion object{
        fun startLoginActivity(context: Context) {
            val intent = Intent(context, LoginActivity::class.java)
            context.startActivity(intent)
        }
    }
}
